package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.user.UserPaidTrack;
import com.atguigu.tingshu.user.service.UserPaidTrackService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "用户已付款声音")
@RestController
@RequestMapping("api/user/userPaidTrack")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserPaidTrackController {

    @Autowired
    private UserPaidTrackService userPaidTrackService;

    /**
     * 根据用户id和专辑id，查询该用户购买过该专辑中的哪几集声音
     *
     * @param userId
     * @param albumId
     * @return
     */
    @GetMapping("/findUserPaidTrack/{userId}/{albumId}")
    public Result<List<UserPaidTrack>> findUserPaidTrack(@PathVariable("userId") Long userId,
                                                         @PathVariable("albumId") Long albumId) {
        List<UserPaidTrack> userPaidTracks = userPaidTrackService.lambdaQuery()
                .eq(UserPaidTrack::getUserId, userId)
                .eq(UserPaidTrack::getAlbumId, albumId)
                .list();
        return Result.ok(userPaidTracks);
    }
}
